package com.dyw.spzx.manager.controller;

import com.dyw.spzx.common.log.annotation.Log;
import com.dyw.spzx.common.log.enums.OperatorType;
import com.dyw.spzx.manager.service.BrandService;
import com.dyw.spzx.model.entity.product.Brand;
import com.dyw.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌管理接口")
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @Operation(summary = "查询所有品牌列表")
    @GetMapping("findAll")
    public Result<List<Brand>> findAll(){
        List<Brand> brandList = brandService.findAll();
        return Result.ok(brandList);
    }


    @Log(title = "品牌列表",businessType = 0,operatorType = OperatorType.MANAGE)
    @Operation(summary = "分页查询所有品牌列表")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable("page")Integer page,@PathVariable("limit") Integer limit){
       PageInfo<Brand> pageInfo =  brandService.findByPage(page,limit);
       return Result.ok(pageInfo);
    }

    @Operation(summary = "添加品牌")
    @PostMapping("/save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.ok(null);
    }

    @Operation(summary = "修改品牌")
    @PutMapping("updateById")
    public Result updateById(@RequestBody Brand brand) {
        brandService.updateById(brand);
        return Result.ok(null);
    }

    @Operation(summary = "删除品牌")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id) {
        brandService.deleteById(id);
        return Result.ok(null);
    }



}
